﻿<?php
class site extends spModel
{	
	var $pk = "siteid";
	var $table = "site";
	var $verifier = array(
		"rules" => array( 
			'domain' => array(
				'notnull' => TRUE,
				'minlength' => 2,
				'maxlength' => 30,
			),
			
			'title' => array(
				'notnull' => TRUE,
				'minlength' => 2,
				'maxlength' => 30,
			),
		),
		"messages" => array(
			'domain' => array(
				'notnull' => "网站域名不能为空",
				'minlength' => "网站域名不能少于3个字符",
				'maxlength' => "网站域名不能大于20个字符"
			),
				
			'title' => array(
				'notnull' => "网站名称不能为空",
				'minlength' => "网站名称不能少于3个字符",
				'maxlength' => "网站名称不能大于20个字符"
			),
		)
		
	);
	
	var $linker = array(
		array(
			'type' => 'hasone',
			'map' => 'site',
			'mapkey' => 'siteid',
			'fclass' => 'record',
			'fkey' => 'siteid',
			'enabled' => false 
		),
		array(
			'type' => 'hasmany',
			'map' => 'record', 
			'mapkey' => 'siteid', 
			'fclass' => 'site',
			'fkey' => 'siteid',
			'enabled' => true
		),
	);
	/**
	 *添加网站 
	 */
	function insert($data)
	{
		$data['userid']=$_SESSION["userinfo"]["userid"];
		$data['addtime']=strtotime(date("Y-m-d H:i:s"));
		$data['lasttime']=strtotime(date("Y-m-d H:i:s"));
        if($this->create($data)){
			return true;			
		} 
		else{
			return false;
		}
	}
	/**
	 *获取当期用户网站 
	 */
	function a_site($page = 1, $pageSize = 10, $grouop)
	{
		if(isset($grouop)){
			$conditions= array(
				"userid" => $_SESSION["userinfo"]["userid"],
				"groupid"=>$grouop
			);
		}else {
			$conditions= array(
				"userid" => $_SESSION["userinfo"]["userid"],
			);
		}
		$result['list'] = $this->spPager($page, $pageSize)->findAll($conditions);
		$result['pagedata'] = $this->spPager()->getPager();
		return $result;
	}
	/**
	 *查询出错的网站 
	 */
	function c_fault()
	{
		$conditions = "status_code<>200";
		$aaa = $this->findAll($conditions,'','siteid');
		$fault = count($aaa);
		return $fault;
	}	
	function c_normal()
	{
		$conditions = "status_code=200";
		$c = $this->findAll($conditions,'','siteid');
		$normal = count($c);
		return $normal;
	}
	/**
	 *首页--查询出错的网站 
	 */
	function b_fault()
	{
		$userid =$_SESSION['userinfo']['userid'];
		$conditions = "status_code<>200 and userid='$userid' and active=1";
		$aaa = $this->findAll($conditions,'','siteid');
		$fault = count($aaa);
		return $fault;
	}	
	function b_normal()
	{
		$userid =$_SESSION['userinfo']['userid'];
		$conditions = "status_code=200 and userid='$userid' and active=1";
		$c = $this->findAll($conditions,'','siteid');
		$normal = count($c);
		return $normal;
	}
	
	
}